﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Tum.CollabXT.VModellXT.Resources;

namespace Tum.CollabXT.VModellXT
{
    public class Topic : ITopic
    {
        #region Private Members
        private string _Id;
        private string _Name;
        private string _Description;
        private Dictionary<string, object> _ExtendedData = new Dictionary<string, object>();
        #endregion

        public Topic(XmlNode node)
        {
            try
            {
                _Id = node.Attributes["id"].Value;
                _Name = node.SelectSingleNode("Name").InnerText;

                XmlNode descNode = null;
                #region Get text block if availabe
                XmlNode descTextIdNode = node.SelectSingleNode("TextbausteinRef/@link");
                if (descTextIdNode != null)
                {
                    descNode = node.OwnerDocument.SelectSingleNode(string.Format(Queries.MDL_GetTextBlock, descTextIdNode.Value));
                    if (descNode != null)
                        ExtendedData["DescriptionRaw"] = descNode.InnerText;
                }
                #endregion

                if (descNode == null)
                {
                    descNode = node.SelectSingleNode("Beschreibung");
                    if (descNode != null)
                        ExtendedData["DescriptionRaw"] = descNode.InnerText;
                }

                _Description = Helper.StripHtmlString(ExtendedData["DescriptionRaw"] as string);
                ExtendedData["DescriptionRaw"] = node.SelectSingleNode("Sinn_und_Zweck").InnerText;
            }
            catch { }
        }

        #region IProcessElement Members

        public string Id
        {
            get { return (_Id); }
            set { _Id = value; }
        }

        public string Name
        {
            get { return (_Name); }
            set { _Name = value; }
        }

        public string Description
        {
            get { return (_Description); }
            set { _Description = value; }
        }

        public Dictionary<string, object> ExtendedData
        {
            get { return _ExtendedData; }
        }

        #endregion
    }
}
